package com.open.capacity.common.util.skf;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.LongByReference;
import com.sun.jna.ptr.PointerByReference;

public interface CLibrary extends Library {

//    HaiTaiUkeyInterface INSTANCE = (HaiTaiUkeyInterface) Native.loadLibrary("SKFAPI31041", HaiTaiUkeyInterface.class);

//    public static final String SKF_DLL_PATH ="D:/Java/program_2021_java/demo_skf_jni/dll/mtoken_gm3000_dky";
    public static final String SKF_DLL_PATH ="SKFAPI31041";
    //CLibrary INSTANCE = (CLibrary) Native.loadLibrary(SKF_DLL_PATH, CLibrary.class);
    CLibrary INSTANCE = (CLibrary) Native.load(SKF_DLL_PATH, CLibrary.class);

    int SKF_EnumDev(boolean input, ByteByReference out, LongByReference len);
    //int SKF_EnumDev(boolean input, PointerByReference out, LongByReference len);

    int SKF_ConnectDev(String input, PointerByReference hDev);
    int SKF_EnumApplication(Pointer hDev, ByteByReference szAppName, LongByReference pulSize);

    int SKF_OpenApplication(Pointer hDev, String pappname, PointerByReference happ);
    int SKF_VerifyPIN(Pointer hApplication, int ulPINType, String szPIN, LongByReference pulRetryCount);

    int SKF_EnumContainer(Pointer hApplication, Struct_CONTAINER szContainerName, LongByReference pulSize);
    //int SKF_EnumContainer(Pointer hApplication, PointerByReference szContainerName, String pulSize);
    //int SKF_EnumContainer(Pointer hApplication, Struct_CONTAINER szContainerName, String pulSize);

    int SKF_OpenContainer(Pointer hApplication, String szContainerName, PointerByReference phContainer);
    int SKF_GetContainerType(Pointer phContainer, LongByReference pulContainerType);
    int SKF_ExportPublicKey(Pointer hContainer, boolean bSignFlag, Struct_ECCPUBLICKEYBLOB pbBlob, LongByReference pulBlobLen);
    int SKF_ExportCertificate(Pointer hContainer, boolean bSignFlag, Struct_ECCCERTBLOB pbCert, LongByReference pulCertLen);
    int SKF_DigestInit(Pointer hdev, int alg_hash, Struct_ECCPUBLICKEYBLOB ecc_pub, String pubid, int ulIDLen, PointerByReference hHash);

    int SKF_Digest(Pointer hHash, String pbData, int ulDataLen, Struct_SM3BLOB pbHashData, LongByReference pulHashLen);
    int SKF_Digest(Pointer hHash, byte[] pbData, int ulDataLen, Struct_SM3BLOB pbHashData, LongByReference pulHashLen);
    int SKF_Digest(Pointer hHash, byte[] pbData, int ulDataLen, Struct_SM3BLOB pbHashData, int pulHashLen);

    int SKF_ECCSignData(Pointer hContainer, Struct_SM3BLOB pbData, int ulDataLen, Struct_ECCSIGNATUREBLOB pSignature);

    int SKF_ECCVerify(Pointer hDev, Struct_ECCPUBLICKEYBLOB pECCPubKeyBlob, Struct_SM3BLOB pbData, int ulDataLen, Struct_ECCSIGNATUREBLOB pSignature);

    int SKF_DisConnectDev(Pointer hDev);
    int SKF_CloseContainer(Pointer hcont);
    int SKF_CloseApplication(Pointer hApplication);
    int SKF_CloseHandle(Pointer hkey);

}
